package gov.mogaha.ntis.cmm.mob.view;

import gov.mogaha.ntis.cmm.mob.R;
import gov.mogaha.ntis.cmm.mob.util.DisPlayMetricsManager;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ButtonView extends LinearLayout{

	private final Context mContext;
	private ImageView mImgView;
	private TextView mTextView;

	
	public ButtonView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		mContext = context;
		init();
	}

	public ButtonView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		mContext = context;
		init();

	}


	private void init(){
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.buttonview, null);
		layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		mTextView = (TextView)layout.findViewById(R.id.txt_select);

		mImgView = (ImageView)layout.findViewById(R.id.btn_select);
		
		
	
		String str = (String)getTag();
		if(str!=null)
		{
			mTextView.setHint(str);
			
		}
		
		int paddingLeft = DisPlayMetricsManager.getPixel(4);
		int paddingRight = DisPlayMetricsManager.getPixel(4);
		int paddingTop = DisPlayMetricsManager.getPixel(2);
		int paddingBottom = DisPlayMetricsManager.getPixel(2);

		setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
		addView(layout);
		

	}
	
	public void setText(String str){
		mTextView.setText(str);
	}
	
	public String getText(){
		return mTextView.getText().toString();

	}
	
	public TextView getTextView(){
		return mTextView;
	}
	
	public ImageView getButton(){
		return mImgView;
	}
	
	public void setEvent(OnClickListener listener){
		mTextView.setOnClickListener(listener);
		mImgView.setOnClickListener(listener);
	}
	
	@Override
	public void setOnClickListener(OnClickListener l) {
		// TODO Auto-generated method stub
		//super.setOnClickListener(l);
		mTextView.setOnClickListener(l);
		mImgView.setOnClickListener(l);
	}
	

}
